<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	<h4 class="modal-title"><font color="red">用户信息</font>&nbsp;</h4>
</div>
<div class="modal-body">
	<form class="form-horizontal" role="form" id="userForm">
		<input type="hidden" name="formToken" id="formToken">
		<input type="hidden" name="userId" id="userId" data-name="userId" class="clean">
		<input type="hidden" name="userPass" id="md5Pass" value=""/>	
		<input type="hidden" name="randCodeMark" value="F">
		<input type="hidden" name="deptId" id="userForm_deptId" data-name="deptId" class="clean">
		<input type="hidden" name="orgId" id="userForm_orgId" data-name="orgId" class="clean">
		<input type="hidden" name="userType" value="member">
		<input type="hidden" name="delStatus" value="0" class="clean">
		<div class="box-body" id="userFormData">
			<div class="form-group">
			   <label for="inputOrgCname" class="col-sm-2 control-label" >账号</label>
			   <div class="col-sm-8">
			       <input type="text" class="form-control clean" data-name="userEname" name="userEname" required placeholder="必填项">
			   </div>
			</div>
			<div class="form-group">
			    <label class="col-sm-2 control-label">姓名</label>
			    <div class="col-sm-8">
			         <input type="text" class="form-control clean"  name="userCname" data-name="userCname" required placeholder="必填项">
			    </div>
			</div>
			<div id="if_update_pass_div" class="form-group" style="display: none">
			    <label class="col-sm-2 control-label">是否修改密码</label>
			    <div class="col-sm-8">
			       <input type="radio" name="if_update_pass" id="if_update_pass" value="1" onclick="setUserPass('1')"/>是
                   <input type="radio" name="if_update_pass" id="if_update_pass1" value="0" checked="checked" onclick="setUserPass('0')"/>否
			    </div>
			</div>
			<div id="edit_user_pass">
			<div class="form-group">
			     <label class="col-sm-2 control-label">密码</label>
			     <div class="col-sm-8">
			         <input type="password" class="form-control clean" id="password">
			     </div>
			</div>
			<div class="form-group">
			     <label class="col-sm-2 control-label">确认密码</label>
			     <div class="col-sm-8">
			           <input type="password" class="form-control clean" id="password2"  type="password">
			     </div>
			 </div>
			 </div>
			 <div class="form-group">
			     <label class="col-sm-2 control-label">邮箱</label>
			     <div class="col-sm-8">
			          <input type="text" class="form-control clean" name="email" data-name="email" placeholder="">
			     </div>
			  </div>
			<!--   <div class="form-group">
			       <label class="col-sm-2 control-label">所属机构</label>
			       <div class="col-sm-8">
			            <select id="orgId" name="orgId" class="form-control" onchange="initDept('deptId',this.value);"></select>
			       </div>
			 </div> -->
			<!-- div class="form-group">
			     <label class="col-sm-2 control-label">上级领导</label>
			     <div class="col-sm-8">
			         <input type="text" class="form-control" name="fax"  placeholder="非必填项">
			     </div>
			 </div-->
			 <div class="form-group">
			      <label class="col-sm-2 control-label">用户性别</label>
			      <div class="col-sm-8" id="userSexDiv"></div>
			 </div>
			 <div class="form-group">
			      <label class="col-sm-2 control-label">手机</label>
			      <div class="col-sm-8">
			           <input type="text" class="form-control clean" name="mobile" data-name=mobile placeholder="非必填项">
			      </div>
			 </div>
			 <!-- 
			 <div class="form-group">
			       <label class="col-sm-2 control-label">联系电话</label>
			       <div class="col-sm-8">
			            <input type="text" class="form-control clean" name="phone" data-name="phone" placeholder="非必填项">
			       </div>
			 </div>
			  -->
			 <div class="form-group">
			      <label class="col-sm-2 control-label">状态</label>
			      <div class="col-sm-8">
			           <input type="radio"  value="1" name="userStatus" checked="checked"/> 启用 
                       <input type="radio" value="0" name="userStatus"/>停用
			      </div>
			  </div>
			  <div class="box-footer">
			        <button type="button" class="btn btn-primary pull-left" onclick="cannel('my_modal');">取消</button>
			        <button type="button" class="btn btn-primary pull-right" onclick="edit('userForm');">提 交</button>
			  </div>
	</form>
</div>
<script>
function toEdit(id){
	cleanData("userForm");
	if(strUtil.isNull(id)){
		layer.alert('请先选中一条数据！', {skin: 'layui-layer-molv',closeBtn: 0 });
		return;
	}else{
	   $("#if_update_pass_div").show();
	   $("#edit_user_pass").hide();
	   $("#if-sysFlag").hide();
	   
		$.ajax({ 
		
			type:'get', url:view_url,
		    data:{'userId':id,'doCode':'U0007'},
		    dataType:'json',
		    success: function(myData){
		    //console.log(myData);
		    
				 getObjInfo(myData);
				 $("#userId").val(myData.userId);
				 var myobj=document.getElementById("userType");
				 if(myobj==null)return;
				 for ( var i = 0; i < myobj.options.length; i++) {
					if (myobj.options[i].value == myData.userType) {
						myobj.selectedIndex = i;
					}
				 }
				 var myobj=document.getElementsByName("userStatus");
				if(myobj==null)return;
				for ( var i = 0; i < myobj.length; i++) {
					if (myobj[i].value == myData.userStatus) {
						myobj[i].checked = "true";
					}
				 }
				 var myobj2=document.getElementsByName("delStatus");
				if(myobj2==null)return;
				for ( var i = 0; i < myobj2.length; i++) {
					if (myobj2[i].value == myData.delStatus) {
						myobj2[i].checked = "true";
					}
				 }
				 
				DictUtil.checkSelectDict("#userType", myData.userType);
				DictUtil.checkSelectDict("#orgId", myData.orgId);
				DictUtil.checkSelectDict("#deptId", myData.deptId);
				 
		  	}
		});	
	}
}

function del(){

	if(strUtil.isNull(id)){
		layer.alert('请先选中一条数据！', {skin: 'layui-layer-molv',closeBtn: 0});
		return;
	}else{
	var index_submit = layer.confirm("您确认删除用户["+userCname+"]吗？", {btn: ['确认','取消'],closeBtn: 0,offset: '220px'}
		, function(){
			layer.close(index_submit);
			var formToken = $("#formToken").val();
			$.ajax({ type:'post', url:del_url,
			    data:{'userId':id,'formToken':formToken}, dataType:'json',
			    success: function(myData){
			    	if(myData.flag=='T'){
			    		layer.alert('删除成功！', { skin: 'layui-layer-molv',closeBtn: 0 });
			    		refresh();
			    	}
			  	}
			});	
		
		});
	}
}

function add(formId){
		var pass = $("#password").val();
	    var pass2 = $("#password2").val();
	    if($.trim(pass) != $.trim(pass2)){
	    	layer.alert('两次输入密码不一致!', { skin: 'layui-layer-molv',closeBtn: 0 });
	    	return;
	    }else{
	    	$("#md5Pass").val(pass.md5());
	    }
	_submit(formId);
}
function edit(formId){
   if(!$("#" + formId)[0].checkValidity()){
		layer.alert('请先完善必输项和必选项！', { skin: 'layui-layer-molv',closeBtn: 0 });
    	return;
	}
   	var item = $('input[name="if_update_pass"]').val(); 
    if("1"==item){
	    var pass = $("#password").val();
    	var pass2 = $("#password2").val();
    	if(!strUtil.isNull(pass)){
	    	if($.trim(pass) != $.trim(pass2)){
	    		layer.alert('两次输入密码不一致!', { skin: 'layui-layer-molv',closeBtn: 0 });
	    		return;
	    	}else{$("#md5Pass").val(pass.md5());}
    	}
	}
	_submit(formId);
}
function _submit(formId){
   $.ajax({type:'post', url:add_url,dataType:'json',
	    data:$("#"+formId).serialize(),
	    success: function(myData){
	    	//console.log(myData);
	    		layer.alert(myData.msg, {skin: 'layui-layer-molv',closeBtn: 0});
	    	if(myData.flag=='T'){
	    		$('#my_modal').modal('hide');
	    		refresh();
	    	}
	  	}
	});	
}
function setUserPass(ifPass){
    if("1"==ifPass){
        $("#edit_user_pass").show();
    }else{
        $("#edit_user_pass").hide();
    }
}

</script>
